use iced::{Element, Length};
use iced::widget::{container, Container, Space};
use crate::theme::CdbTheme;

/// Separator orientation
#[derive(Debug, Clone, Copy)]
pub enum SeparatorOrientation {
    Horizontal,
    Vertical,
}

/// Create a separator line
pub fn separator<'a, Message: 'a>(
    orientation: SeparatorOrientation,
    theme: &'a CdbTheme,
) -> Container<'a, Message> {
    let (width, height) = match orientation {
        SeparatorOrientation::Horizontal => (Length::Fill, Length::Fixed(1.0)),
        SeparatorOrientation::Vertical => (Length::Fixed(1.0), Length::Fill),
    };

    container(Space::new(width, height))
        .style(move |_theme| {
            container::Style {
                background: Some(theme.colors.border.into()),
                border: iced::Border::default(),
                shadow: iced::Shadow::default(),
                text_color: None,
            }
        })
        .width(width)
        .height(height)
}

/// Create a horizontal separator
pub fn horizontal_separator<'a, Message: 'a>(theme: &'a CdbTheme) -> Container<'a, Message> {
    separator(SeparatorOrientation::Horizontal, theme)
}

/// Create a vertical separator
pub fn vertical_separator<'a, Message: 'a>(theme: &'a CdbTheme) -> Container<'a, Message> {
    separator(SeparatorOrientation::Vertical, theme)
}

/// Create a section divider with optional text
pub fn section_divider<'a, Message: 'a>(
    text_content: Option<&'a str>,
    theme: &'a CdbTheme,
) -> Element<'a, Message> {
    use iced::widget::{row, text};
    
    match text_content {
        Some(content) => {
            let left_sep = separator(SeparatorOrientation::Horizontal, theme);
            let right_sep = separator(SeparatorOrientation::Horizontal, theme);
            let label = text(content)
                .size(super::typography::SM)
                .color(theme.colors.muted_foreground);
            
            row![
                left_sep,
                container(label).padding([0, super::spacing::MD]),
                right_sep
            ]
            .align_y(iced::Alignment::Center)
            .spacing(0)
            .into()
        }
        None => separator(SeparatorOrientation::Horizontal, theme).into(),
    }
}
